package com.zhilianbao.leyaogo.utils;

import android.util.DisplayMetrics;
import android.view.View;
import android.widget.RelativeLayout;

import com.bql.roundview.RoundTextView;

/**
 * 购物车数量显示工具
 */
public class ShopNumUtils {

    public static void show(RoundTextView numView, int num) {
        if (numView == null) {
            return;
        }
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) numView.getLayoutParams();
        DisplayMetrics dm = numView.getResources().getDisplayMetrics();
        if (num <= 0) {
            numView.clearAnimation();
            numView.setVisibility(View.GONE);
        } else {
            numView.setVisibility(View.VISIBLE);
            lp.height = (int) (15 * dm.density);

            if (num > 0 && num < 10) {
                lp.width = (int) (15 * dm.density);
                numView.setPadding((int) (3 * dm.density), 0, (int) (3 * dm.density), 0);
                numView.setText(num + "");
            } else if (num > 9 && num < 100) {
                lp.width = (int) (20 * dm.density);
                numView.setPadding((int) (3 * dm.density), 0, (int) (3 * dm.density), 0);
                numView.setText(num + "");
            } else {//数字超过两位,显示99+
                lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
                numView.setPadding((int) (3 * dm.density), 0, (int) (3 * dm.density), 0);
                numView.setText("99+");
            }
            numView.setLayoutParams(lp);
        }
    }
}
